package com.fyakm.daodejing.simple.stockTest;

import com.fyakm.daodejing.simple.stockTest.util.StockTradingUtils;
import com.fyakm.daodejing.simple.stockTest.util.StockUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


/**
 * 测试多个股票随机交易
 */
public class TestStock {

    public static void main(String[] args) {
        // 股票数据目录
        String dir = "D:\\share\\A股数据";

        // 读取目录下的所有股票文件
        File directory = new File(dir);
        File[] files = directory.listFiles((dir1, name) -> name.endsWith(".csv"));


        int i = 0;
        List<StockTradingUtils.TradingResult> resultList = new ArrayList<>();
        // 遍历每个股票文件
        for (File file : files) {
            System.out.println("开始计算第"+i+"个股票："+file.getName()+"---------");
            String stockCode = file.getName().replace(".csv", "");
            StockTradingUtils.TradingResult tradingResult = StockUtil.testStock(stockCode, "2000-01-01", "2025-01-01");
            resultList.add(tradingResult);

            if(i++ > 5000){
                break;
            }

        }
//        StockUtil.testStock("000001","2022-01-01","2023-01-01");


        System.out.println("\n\n最终结果:\n======================================");
        // 输出结果
        for (StockTradingUtils.TradingResult result : resultList) {
            System.out.println(result);
            System.out.println("-----------------------");
        }


        System.out.println("分析盈亏结果：\n\n");
        // 分析结果
        StockTradingUtils.analyzeProfit(resultList);

    }
}